<?php

function page_contact_form($form,&$form_state) {
    $form = array();
    $form['title'] = array(
        '#type' => 'select',
        '#title' => 'Title',
        '#options' => array(
            'Mrs' => t('Mrs'),
            'Ms' => t('Ms'),
            'Mr' => t('Mr'),
        ),
        '#default_value' => 'Mr',
        '#required' => TRUE,
    );
    $form['country'] = array(
        '#type' => 'select',
        '#title' => 'Country',
        '#options' => Contact::getCountry(),
        '#default_value' => 'vn',
        '#required' => TRUE,
    );
    $form['message'] = array(
        '#title' => t('Message'),
        '#type' => 'textarea',
        '#required' => TRUE,
    );
    $form['name'] = array(
        '#type' => 'textfield',
        '#title' => t('Name'),
        '#size' => 30,
        '#maxlength' => 128,
        '#required' => TRUE,
    );
    $form['phone'] = array(
        '#type' => 'textfield',
        '#title' => t('Phone'),
        '#size' => 30,
        '#maxlength' => 128,
        '#required' => TRUE,
    );
    $form['phone'] = array(
        '#type' => 'textfield',
        '#title' => t('Phone'),
        '#size' => 30,
        '#maxlength' => 128,
        '#required' => TRUE,
    );
    $form['company'] = array(
        '#type' => 'textfield',
        '#title' => t('Company'),
        '#size' => 30,
        '#maxlength' => 128,
        '#required' => TRUE,
    );
    $form['job_position'] = array(
        '#type' => 'textfield',
        '#title' => t('Job Position'),
        '#size' => 30,
        '#maxlength' => 128,
        '#required' => TRUE,
    );
    $form['email'] = array(
        '#type' => 'textfield',
        '#title' => t('Email'),
        '#size' => 30,
        '#maxlength' => 128,
        '#required' => TRUE,
    );
    $form['subject'] = array(
        '#type' => 'textfield',
        '#title' => t('Subject'),
        '#size' => 30,
        '#maxlength' => 128,
        '#required' => TRUE,
    );
    $form['captch'] = array(
        '#type' => 'textfield',
        '#title' => t('Captch'),
        '#size' => 30,
        '#maxlength' => 128,
        '#required' => TRUE,
    );
     $form['buttoms']['border'] = array(
        '#type' => 'item',
        '#value' => ''
    );
    $form['buttoms']['submit'] = array(
        '#type' => 'submit',
        '#value' => ''
    );

    return $form;
}
function page_contact_form_validate($form, &$form_state){
    if(!valid_email_address($form_state['values']['email'])){
        form_set_error('email', 'Your email address appears malformed');
    }
}
function page_contact_form_submit($form, &$form_state) {
    $title = $form_state['values']['title'];
    $country = $form_state['values']['country'];
    $message = $form_state['values']['message'];
    $name = $form_state['values']['name'];
    $phone = $form_state['values']['phone'];
    $company = $form_state['values']['company'];
    $job = $form_state['values']['job_position'];
    $email = $form_state['values']['email'];
    $subject = $form_state['values']['subject'];
    $captch = $form_state['values']['captch'];
    db_insert('customer_service')
    ->fields(array('title','name','company','email','country','phone','job_position','subject','message','captch'))
            ->values(array(
               'title' => $title,
                'name'=>$name,
                'company'=>$company,
                'email'=>$email,
                'country'=>$country,
                'phone'=>$phone,
                'job_position'=>$job,
                'subject'=>$subject,
                'message'=>$message,
                'captch'=>$captch,
            ))
            ->execute();
     drupal_set_message(t('The message has been sended.'));
}
?>
